package zzhyc.keystore

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.bytedance.sdk.openadsdk.TTAdSdk
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import zzhyc.keystore.databinding.ActivityMainBinding
import zzhyc.keystore.databinding.ActivityWelcomeBinding

private const val TAG = "MainActivity"

class MainActivity : AppCompatActivity() {

    private val binding by lazy { ActivityMainBinding.inflate(layoutInflater) }
    private var index = 0

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)
    }

    override fun onWindowFocusChanged(hasFocus: Boolean) {
        super.onWindowFocusChanged(hasFocus)
        if (hasFocus && index == 0) {
            index += 1
            runBlocking {
                delay(1200)
                startActivity(Intent(this@MainActivity, WelcomeActivity::class.java))
                finish()
            }
        }
    }

    override fun onResume() {
        super.onResume()
        Log.i(TAG, "--onResume-------")
        val isReady = TTAdSdk.isSdkReady()
        Log.i(TAG, "isReady-- $isReady")
    }
}